#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

typedef pair<int, int> PII;

const int N = 5010, INF = 0x3f3f3f3f;
int dist[N];
bool st[N];
vector<PII> edges[N];
int n, m;

int prim()
{
	memset(dist,0x3f, sizeof dist);
	dist[1] = 0;
	int ret = 0;
	for(int i = 1; i <= n; i++)
	{
		int t = 0;
		for(int j = 1; j <= n; j++)
			if(!st[j] && dist[j] < dist[t])
			t = j;
		
		if(dist[t] == INF) return INF;
		st[t] = true;
		ret += dist[t]; 
		
		for(auto x : edges[t])
		{
			int a = x.first, b = x.second;
			dist[a] = min(dist[a], b);
		}
	}
	return ret;
}

int main()
{
	cin >> n >> m;
	for(int i = 1; i <= m; i++)
	{
		int a, b, c; cin >> a >> b >> c;
		edges[a].push_back({b, c});
		edges[b].push_back({a, c});
	}
	int ret = prim();
	if(ret == INF) cout << "orz" << endl;
	else cout << ret << endl;
	return 0;
}

